﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Runtime.Serialization;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Should;

namespace NGeo.Yahoo.PlaceFinder
{
    [TestClass]
    public class ResultsTests
    {
        [TestMethod]
        public void Yahoo_PlaceFinder_Results_ShouldBePublic()
        {
            var model = new Results();
            model.ShouldNotBeNull();
        }

        [TestMethod]
        public void Yahoo_PlaceFinder_Results_ShouldImplementGenericIEnumerable()
        {
            var model = new Results
            {
                Items = new List<Result>
                {
                    new Result(), new Result(), new Result(),
                },
            };


            model.ShouldImplement(typeof(IEnumerable<Result>));
            model.GetEnumerator().ShouldNotBeNull();
            ((IEnumerable)model).GetEnumerator().ShouldNotBeNull();
            foreach (var item in model)
            {
                item.ShouldNotBeNull();
            }
        }

        [TestMethod]
        public void Yahoo_PlaceFinder_Results_ShouldHaveDataContractAttribute()
        {
            Attribute.IsDefined(typeof(Results), typeof(DataContractAttribute))
                .ShouldBeTrue();
        }

        [TestMethod]
        public void Yahoo_PlaceFinder_StringProperties_ShouldHaveDataContractAttribute()
        {
            var properties = new Dictionary<string, Expression<Func<Results, string>>>
            {
                { "ErrorMessage", p => p.ErrorMessage },
                { "Locale", p => p.Locale },
            };

            properties.ShouldHaveDataMemberAttributes();
        }

        [TestMethod]
        public void Yahoo_PlaceFinder_Results_IntProperties_ShouldHaveDataContractAttribute()
        {
            var properties = new Dictionary<string, Expression<Func<Results, int>>>
            {
                { "Error", p => p.ErrorCode },
                { "Found", p => p.Found },
                { "Quality", p => p.Quality },
            };

            properties.ShouldHaveDataMemberAttributes();
        }

        [TestMethod]
        public void Yahoo_PlaceFinder_Results_Items_ShouldHaveDataContractAttribute()
        {
            var properties = new Dictionary<string, Expression<Func<Results, List<Result>>>>
            {
                { "Results", p => p.Items },
            };

            properties.ShouldHaveDataMemberAttributes();
        }

    }
}
